Skip to content

Apply Palantir Java Format to the entire codebase + enforce on every build#1773

Merged
tfenne merged 2 commits into
devfrom
tf_code_formatter
Apr 25, 2026
Merged

Apply Palantir Java Format to the entire codebase + enforce on every build#1773
tfenne merged 2 commits into
devfrom
tf_code_formatter

Conversation

@tfenne
Copy link
Copy Markdown
Member

@tfenne tfenne commented Apr 25, 2026

Summary

Closes #1761.

This is a doozy on purpose: it brings every .java file in the repo under a single mechanical code style (Palantir Java Format) and wires up the build so the codebase stays that way going forward.

The PR is structured as two commits, no squash, so both flow into dev:

  1. Apply Palantir Java Format to entire codebase — 1155 files reformatted. No behavior changes. The single non-mechanical edit is the removal of one stray // the imports for unit testing. comment in VariantContextUnitTest.java that was preventing the formatter from treating an import block as contiguous.
  2. Add Spotless + Palantir Java Format and auto-format on every build — adds the Spotless Gradle plugin configured with palantirJavaFormat(); hooks spotlessJavaApply into compileJava so local builds auto-rewrite unformatted source in place; adds a CI formatCheck job that runs spotlessCheck (verify-only) as the actual enforcement boundary; adds a Code Style section to CONTRIBUTING.md; adds .git-blame-ignore-revs pointing at commit 1; deletes the stale java-style-eclipse.xml and java-style-intellij.xml.

Local DX

Local builds fix formatting rather than fail on it -- contributors don't need to remember to run a formatter command. CI separately verifies (no mutation), so unformatted code still can't slip into dev.

spotlessJavaApply is sub-second warm thanks to Gradle's up-to-date checking, so the cost on every compile is negligible.

Git blame

.git-blame-ignore-revs points at the bulk-format commit. GitHub honors it automatically in the web UI. Locally, run once per clone:

git config blame.ignoreRevsFile .git-blame-ignore-revs

This is documented in the new CONTRIBUTING.md section.

Test plan

  • ./gradlew compileJava compileTestJava -- passes
  • ./gradlew test -- 21,936 / 21,936 pass
  • ./gradlew spotbugsMain spotbugsTest -- clean
  • Verified compileJava rewrites unformatted source in place (smoke-tested on a deliberately-malformed file)
  • Verified git blame with --ignore-revs-file .git-blame-ignore-revs credits the original authors, not the reformat commit
  • CI: confirm formatCheck job is green
  • CI: confirm existing test / testExternalApis / spotBugs jobs still green

tfenne added 2 commits April 25, 2026 08:26
This is a mechanical reformat of every .java file under src/ via the
Palantir Java Format style. There are no behavior changes.

The follow-up commit adds the Spotless Gradle plugin that produced this
output, wires it into the build as an enforcement step, updates the
contributor docs, deletes the obsolete java-style-eclipse.xml and
java-style-intellij.xml style guides, and adds .git-blame-ignore-revs
so this commit is skipped by `git blame`.

The single non-mechanical change in this commit is the removal of one
stray "// the imports for unit testing." comment from
VariantContextUnitTest.java that was preventing the formatter from
treating the surrounding imports as a contiguous block. The comment
carried no information.

Part of #1761.
…1761)

All build, CI, and contributor-facing changes for the new code-style
enforcement. The bulk reformat itself is in the previous commit; this
commit only contains setup.

build.gradle:
- Add the com.diffplug.spotless plugin (8.4.0), configured with
  palantirJavaFormat() over src/**/*.java. There are no formatter
  knobs -- the formatter is the style guide.
- Make compileJava depend on spotlessJavaApply so any unformatted
  source is auto-rewritten in place during the build. Contributors
  don't have to remember to run a format command -- just build, and
  the source ends up formatted. spotlessJavaApply is sub-second warm
  thanks to Gradle's up-to-date checking, so the cost on every build
  is negligible.

.github/workflows/tests.yml:
- Add a `formatCheck` CI job running `./gradlew spotlessCheck`
  (verify-only, no mutation) so unformatted code can't slip past CI.
  The local auto-format is a convenience; CI is the enforcement
  boundary.

CONTRIBUTING.md:
- New "Code Style" section: how the auto-format works, when/why you
  might still want to run `spotlessApply` directly, that CI verifies
  rather than rewrites, and how to opt in to .git-blame-ignore-revs
  locally.

.git-blame-ignore-revs:
- New file pointing at the bulk-format commit so `git blame` (and the
  GitHub web blame view, which honors the file automatically) credits
  the original author of each line rather than the reformat commit.

Deletions:
- java-style-eclipse.xml and java-style-intellij.xml -- stale,
  unreferenced by the build, and inconsistent with Palantir's output.

Closes #1761.
@tfenne
Copy link
Copy Markdown
Member Author

tfenne commented Apr 25, 2026

Fixes #1761

@tfenne tfenne merged commit bb5cce8 into dev Apr 25, 2026
4 checks passed
@tfenne tfenne deleted the tf_code_formatter branch April 25, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant